<%@page import="com.kamus.manager.PasanganKataIGMgr" %>
<%@page import="com.kamus.manager.PasanganKataGIMgr" %>
<%@page import="com.kamus.model.PasanganKata" %>
<%@page import="com.kamus.Constants" %>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Input Data Kosakata</title>
    </head>
    <body>
        <h1>Input Kosakata</h1>
        <form action="KosakataServlet" method="POST">
            Lebih dari satu pisahkan dengan tanda titik koma ';'

            <%if (request.getParameter(Constants.TYPE) == null) {%>
            <table>
                <tr>
                    <td>Orientasi</td>
                    <td><select name="orientation">
                            <option value="0">GAUL-IND</option>
                            <option value="1">IND-GAUL</option>
                            <option value="2">REVERSE</option>
                        </select>
                    </td>
                </tr>
                <tr>
                    <td>Bahasa Gaul</td>
                    <td><input type="text" name="gaul" value=""/></td>
                </tr>
                <tr>
                    <td>Bahasa Indonesia</td>
                    <td><input type="text" name="indonesia" value=""/></td>
                </tr>
                <tr>
                    <td></td>
                    <td><input type="submit" name="<%=Constants.ACTION%>" value="<%=Constants.ADD%>" /></td>
                </tr>
            </table>
            <%
            }
            else  {
                String type = request.getParameter(Constants.TYPE);
                String id = request.getParameter(Constants.ID);
                String giSelected="false";
                String igSelected="false";
                PasanganKata pKata=null;
                if (type.equals(Constants.IND_GAUL)) {
                    igSelected="true";
                    pKata = PasanganKataIGMgr.getInstance().getKata(id);
                } else if (type.equals(Constants.GAUL_IND)) {
                    giSelected="true";
                    pKata = PasanganKataGIMgr.getInstance().getKata(id);
                }
            %>
            <input type="hidden" name="<%=Constants.TYPE%>" value="<%=type%>">
            <input type="hidden" name="<%=Constants.ID%>" value="<%=id%>">
            <table>
                <tr>
                    <td>Orientasi</td>
                    <td><select name="orientation" disabled="true">
                            <option value="0" selected="<%=giSelected%>">GAUL-IND</option>
                            <option value="1" selected="<%=igSelected%>">IND-GAUL</option>
                            <option value="2">REVERSE</option>
                        </select>
                    </td>
                </tr>
                <tr>
                    <td>Bahasa Gaul</td>
                    <td><input type="text" name="gaul" value="<%=pKata.getGaul()%>"/></td>
                </tr>
                <tr>
                    <td>Bahasa Indonesia</td>
                    <td><input type="text" name="indonesia" value="<%=pKata.getIndonesia()%>"/></td>
                </tr>
                <tr>
                    <td></td>
                    <td><input type="submit" name="<%=Constants.ACTION%>"value="<%=Constants.EDIT%>" /></td>
                </tr>
            </table>
            <% }%>
        </form>
    </body>
</html>
